package com.fg.cloud.common;

import java.text.DecimalFormat;
import java.util.Date;

import org.apache.commons.lang3.time.DateFormatUtils;

/**
 * Description:编码规则工具类
 * @author around
 * @date 2017年9月6日下午3:42:15
 */
public class NumberUtil {

	static DecimalFormat format = new DecimalFormat("00000000");
	
	/** 订单编码 */
	public static final String ORDER = "DD";
	/** 发货单编码 */
	public static final String ORDER_DELIVE = "FH";
	/** 退货单编码 */
	public static final String ORDER_RETURN = "TH";
	/** 流水号 */
	public static final String CAPITAL = "LS";
	/** 流水号 */
	public static final String STATEMENT = "DZ";
	
	/**
	 * 随机生成UUID
	 * 
	 * @return
	 */
	public synchronized static String UUID() {
		return java.util.UUID.randomUUID().toString();
	}
	
	/**
	 * Description:编码规则
	 * @param before
	 * @return
	 * @author around
	 * @date 2017年9月7日下午1:49:07
	 */
	public synchronized static String getNumber(String before) {
		String time = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
		return before.concat(time).concat(getRandomInt());
	}
	
	/**
	 * Description:生成流水号编码 SN2017090711591300066293
	 * @return
	 * @author around
	 * @date 2017年9月6日下午3:48:49
	 */
	public synchronized static String getSerialNumber() {
		String time = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
		return CAPITAL.concat(time).concat(getRandomInt());
	}
	
	public synchronized static String getOrderNumber() {
		String time = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
		return ORDER.concat(time).concat(getRandomInt());
	}
	
	public synchronized static String getOrderDeliveNumber() {
		String time = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
		return ORDER_DELIVE.concat(time).concat(getRandomInt());
	}
	
	public synchronized static String getOrderReturnNumber() {
		String time = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
		return ORDER_RETURN.concat(time).concat(getRandomInt());
	}
	
	public synchronized static String getStatementNumber() {
		String time = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
		return STATEMENT.concat(time).concat(getRandomInt());
	}

	
	/**
	 * Description:生成随机数
	 * @return
	 * @author around
	 * @date 2017年9月7日上午11:58:33
	 */
	public synchronized static String getRandomInt() {
		return format.format(Math.random() * 1000000);
	}
	
	
	public static void main(String[] args) {
		System.out.println(java.util.UUID.randomUUID());
		System.out.println(getSerialNumber());
		System.out.println(getSerialNumber());
		System.out.println(getSerialNumber());
		System.out.println(getRandomInt());
	}
}
